package com.itheima.service.impl;

import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.CountOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 员工性别数据
     * @return
     */
    @Override
    public List<Map<String, Object>> empGenderData() {
//        调用Mapper层,员工性别统计
        List<Map<String,Object>> list = empMapper.empGenderData();
        return list;
    }

    /**
     * 员工职位数据
     * @return
     */
    @Override
    public JobOption empJobData() {
        List<Map<String,Object>> list = empMapper.empJobData();

//        数据处理,封装成JobOption对象
        List<Object> jobList = list.stream().map(map -> map.get("name")).toList();

        List<Object> dataList = list.stream().map(map -> map.get("value")).toList();

        return new JobOption(jobList,dataList);
    }


    /**
     * 学员学历数据
     * @return
     */
    @Override
    public List<Map<String, Integer>> studentDegreeData() {
//        1.调用Mapper层方法
        List<Map<String, Integer>> list = studentMapper.studentDegreeData();
        return list;
    }


    /**
     * 班级人数数据
     * @return
     */
    @Override
    public CountOption studentCountData() {

        // 1. 查询每个班级人数
        List<Map<String,Object>> countList = studentMapper.getCountList();
//        2.转成流对象，map映射取出键为name的值存入集合
        List<Object> clazzList = countList.stream().map(count -> count.get("name")).toList();
//        3.取出所有键为value的值存入集合
        List<Object> dataList = countList.stream().map(count -> count.get("value")).toList();

//        4.返回数据给Controller层
        return new CountOption(clazzList, dataList);
    }
}
